package com.gagakuai.engine.impl.cfg;

import com.gagakuai.engine.impl.interceptor.Command;
import com.gagakuai.engine.impl.interceptor.CommandConfig;
import com.gagakuai.engine.impl.interceptor.CommandExecutor;
import com.gagakuai.engine.impl.interceptor.CommandInterceptor;

/*
 * @program: common-starters
 * @description: 命令执行器实现类
 * @author: houhong
 * @create: 2023-01-02 15:04
 */
public class CommandExecutorImpl implements CommandExecutor {

    private final CommandConfig commandConfig;

    private final CommandInterceptor first;

    public CommandExecutorImpl(CommandConfig commandConfig, CommandInterceptor first) {
        this.commandConfig = commandConfig;
        this.first = first;
    }

    public CommandInterceptor getFirst() {
        return first;
    }

    @Override
    public CommandConfig getDefaultConfig() {
        return this.commandConfig;
    }

    @Override
    public <T> T execute(CommandConfig config, Command<T> command) {

        return first.execute(config,command);
    }

    @Override
    public <T> T execute(Command<T> command) {
        return first.execute(getDefaultConfig(),command);
    }
}